import socket
import struct
import random
import time

def send_neighbor_solicitation(interface, target_ip):
    # 创建IPv6 UDP套接字
    sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)

    # 准备IPv6邻居请求
    ipv6_header = b'\x60\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00'
    neighbor_solicitation = b'\x88\x00\x00\x00' + b'\x00' * 12

    # 组装IPv6报文
    packet = ipv6_header + neighbor_solicitation

    # 发送邻居请求到目标IP地址
    while True:
        sock.sendto(packet, (target_ip, 0, 0, interface))
        print("发送IPv6邻居请求到", target_ip)
        time.sleep(0.1)  # 控制发送速率

if __name__ == "__main__":
    try:
        # 获取用户输入的网络接口名称和目标IPv6地址
        interface = input("请输入网络接口名称：")
        target_ip = input("请输入目标IPv6地址：")

        # 发送邻居请求
        send_neighbor_solicitation(interface, target_ip)
    except KeyboardInterrupt:
        print("\033[1;31;40m[*]用户中断程序")
        print("\033[1;37;40m")
    except Exception as e:
        print("\033[1;31;40m[*]发生错误:", e)
        print("\033[1;37;40m")
